package cn.com.jenson.web.user.controller;

import cn.com.jenson.common.BasicController;
import cn.com.jenson.common.ImportVerifierVo;
import cn.com.jenson.common.Result;
import cn.com.jenson.common.SelectVo;
import cn.com.jenson.dao.user.bo.UserBo;
import cn.com.jenson.dao.user.searchBo.UserSearchBo;
import cn.com.jenson.dao.user.vo.UserVo;
import cn.com.jenson.service.user.service.UserService;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/user")
public class UserController implements BasicController<UserVo, UserBo, UserSearchBo> {

    @Resource
    private UserService userService;

    @Override
    public Result<Page<UserVo>> pageAll(@RequestBody UserSearchBo userSearchBo) {
        return Result.suc(userService.pageAll(userSearchBo));
    }

    @Override
    public Result<List<UserVo>> listAll(@RequestBody UserSearchBo userSearchBo) {
        return Result.suc(userService.listAll(userSearchBo));
    }

    @Override
    public Result<UserVo> get(@RequestBody UserSearchBo userSearchBo) throws InstantiationException, IllegalAccessException {
        return Result.suc(userService.get(userSearchBo));
    }

    @Override
    public Result<UserVo> edit(@RequestBody UserBo userBo) throws InstantiationException, IllegalAccessException {
        return Result.suc(userService.edit(userBo));
    }

    @Override
    public Result<List<UserVo>> editAll(@RequestBody List<UserBo> userBos) {
        return Result.suc(userService.editAll(userBos));
    }

    @Override
    public Result<UserVo> deleted(@RequestBody UserSearchBo userSearchBo) throws InstantiationException, IllegalAccessException  {
        return Result.suc(userService.deleted(userSearchBo));
    }

    @Override
    public Result<List<UserVo>> deletedAll(@RequestBody List<UserSearchBo> userSearchBos) throws InstantiationException, IllegalAccessException  {
        return Result.suc(userService.deletedAll(userSearchBos));
    }

    @Override
    public List<ImportVerifierVo> importTemplateVerifiers() {
        return userService.importTemplateVerifiers();
    }

    @Override
    public void importTemplateDownload(HttpServletResponse response) throws IOException {
        userService.importTemplateDownload(response);
    }

    @Override
    public Result<List<SelectVo<String, Integer, UserVo>>> option() {
        return Result.suc(userService.option());
    }
}
